package com.javabasic.algorithm.leetcode;

import java.util.Arrays;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/7/11 23:03
 * @Version 1.0
 **/
public class MinimumDifferenceBetweenLargestAndSmallestValueInThreeMoves {

    public int minDifference(int[] nums) {
        int length = nums.length;
        int left = 0, right = length-1;
        Arrays.sort(nums);
        for (int i = 1; i <= nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
        int k = 0;
        while (k < 3 && left < right) {
            k++;
            if (nums[left+1] - nums[left] >= nums[right]-nums[right-1]) {
                left++;
            } else {
                right--;
            }
        }
        if (k < 3) return 0;
        return nums[right]-nums[left];
    }
}
